package avicit.bdp.dgs.qa.service.algo.process.data;

import avicit.bdp.dgs.qa.dto.FCTemplateDTO;
import avicit.bdp.dgs.qa.dto.FtdpFileDTO;
import avicit.bdp.dgs.qa.dto.JobDTO;
import avicit.bdp.dgs.qa.dto.RuleDTO;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * UT测试
 */
public class ProcessDataAlgoTest {
    /**
     * 测试前，初始化数据
     */
    @Before
    public void beforTest() {

    }

    /**
     * 测试后，清理数据
     */
    @After
    public void afterTest() {

    }

    /**
     * 测试试飞工程值数据算法（正常用例）
     */
    @Test
    public void testCase1() {
        // 构造模拟数据
        JobDTO jobDTO = mockJob();
        List<RuleDTO> ruleList = mockRuleList();
        List<FtdpFileDTO> fileList = mockFileList();
        List<FCTemplateDTO> fileTemplateList = mockFileTemplate();

        // 方法调用
        ResponseMsg<List<FtdpFileDTO>> result = new ProcessDataAlgo().execute(jobDTO, ruleList);

        // 执行试飞工程值数据校验算法
        System.out.println(JSONObject.toJSONString(result));
    }

    /**
     * 测试试飞工程值数据算法（异常用例）
     */
    @Test
    public void testCase2() {

    }

    /**
     * 模拟文件校验任务
     *
     * @return
     */
    private JobDTO mockJob() {
        String jobJsonString = "{\n" +
                "\t\"id\": \"8a58bcf68b41dbb2018b6b29365624f3\",\n" +
                "\t\"name\": \"工程值数据校验-自动创建-001\",\n" +
                "\t\"offsiteDataId\": \"8a58bcf68b45edaa018b6b2693141df1\",\n" +
                "\t\"fileType\": 1,\n" +
                "\t\"fileTypeName\": \"工程值数据\",\n" +
                "\t\"dataProp\": null,\n" +
                "\t\"type\": null,\n" +
                "\t\"typeName\": null,\n" +
                "\t\"modelCode\": \"XH001\",\n" +
                "\t\"aircraftName\": null,\n" +
                "\t\"sortie\": \"1\",\n" +
                "\t\"flightDate\": \"2023-10-10\",\n" +
                "\t\"testSystemName\": \"1号测试系统\",\n" +
                "\t\"fileIdList\": null,\n" +
                "\t\"resourceIds\": \"8a58bcf68b45edaa018b6b2694591df3,8a58bcf68b45edaa018b6b2694991df4\"\n" +
                "}";

        System.out.println(jobJsonString);
        return JSONObject.parseObject(jobJsonString, JobDTO.class);
    }

    /**
     * 模拟规则列表
     *
     * @return
     */
    private List<RuleDTO> mockRuleList() {
        String ruleJsonString = "{\n" +
                "\t\"createdBy\": \"平台管理员\",\n" +
                "\t\"creationDate\": \"2023-10-26 16:46:00\",\n" +
                "\t\"lastUpdateDate\": \"2023-10-26 16:46:00\",\n" +
                "\t\"lastUpdatedBy\": \"1\",\n" +
                "\t\"version\": 0,\n" +
                "\t\"orgIdentity\": \"ORG_ROOT\",\n" +
                "\t\"id\": \"8a58bcf68b6b1f40018b6b29719c01d7\",\n" +
                "\t\"jobId\": \"8a58bcf68b41dbb2018b6b29365624f3\",\n" +
                "\t\"name\": \"工程值校验模板\",\n" +
                "\t\"measureType\": 3,\n" +
                "\t\"measureTypeName\": \"文件校验\",\n" +
                "\t\"templateType\": 0,\n" +
                "\t\"templateTypeName\": \"内置模板\",\n" +
                "\t\"templateId\": \"8a58a6c788ae86d20188aee282df0017\",\n" +
                "\t\"templateName\": \"试飞工程值数据校验\",\n" +
                "\t\"weight\": 10,\n" +
                "\t\"weightRatio\": 1\n" +
                "}";
        List<RuleDTO> ruleList = new ArrayList<>();
        ruleList.add(JSONObject.parseObject(ruleJsonString, RuleDTO.class));

        return ruleList;
    }

    /**
     * 模拟文件列表
     *
     * @return
     */
    private List<FtdpFileDTO> mockFileList() {
        String fileJsonString1 = "{\n" +
                "\t\"fullName\": \"test.txt\",\n" +
                "\t\"pid\": \"8a58bcf68b45edaa018b6b2693141df1\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"directory\": 0,\n" +
                "\t\"size\": 36,\n" +
                "\t\"name\": \"test.txt\",\n" +
                "\t\"fileId\": \"8a58bcf68b45edaa018b6b2694591df3\"\n" +
                "}";
        String fileJsonString2 = "{\n" +
                "\t\"fullName\": \"train1.csv\",\n" +
                "\t\"pid\": \"8a58bcf68b45edaa018b6b2693141df1\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"directory\": 0,\n" +
                "\t\"size\": 1462,\n" +
                "\t\"name\": \"train1.csv\",\n" +
                "\t\"fileId\": \"8a58bcf68b45edaa018b6b2694991df4\"\n" +
                "}";
        String fileJsonString3 = "{\n" +
                "\t\"fullName\": \"train1.pcm\",\n" +
                "\t\"pid\": \"8a58bcf68b45edaa018b6b2693141df1\",\n" +
                "\t\"type\": 0,\n" +
                "\t\"directory\": 0,\n" +
                "\t\"size\": 1462,\n" +
                "\t\"name\": \"train1.pcm\",\n" +
                "\t\"fileId\": \"8a58bcf68b45edaa018b6b2694991df6\"\n" +
                "}";
        List<FtdpFileDTO> fileList = new ArrayList<>();

        fileList.add(JSONObject.parseObject(fileJsonString1, FtdpFileDTO.class));
        fileList.add(JSONObject.parseObject(fileJsonString2, FtdpFileDTO.class));
        fileList.add(JSONObject.parseObject(fileJsonString3, FtdpFileDTO.class));

        return fileList;
    }

    /**
     * 模拟文件模板
     *
     * @return
     */
    private List<FCTemplateDTO> mockFileTemplate() {
        String templateJsonString = "[{\n" +
                "\t\"code\": \"2\",\n" +
                "\t\"fieldList\": [{\n" +
                "\t\t\"id\": \"8a58bcf68b5b6183018b6b50d1e300a1\",\n" +
                "\t\t\"name\": \"abc\",\n" +
                "\t\t\"templateId\": \"8a58a6c787c1e8e30187e4b3edd404ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58bcf68b5b6183018b6b50d1e300a2\",\n" +
                "\t\t\"name\": \"def\",\n" +
                "\t\t\"templateId\": \"8a58a6c787c1e8e30187e4b3edd404ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58bcf68b5b6183018b6b50d1e300a3\",\n" +
                "\t\t\"name\": \"ghi\",\n" +
                "\t\t\"templateId\": \"8a58a6c787c1e8e30187e4b3edd404ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}],\n" +
                "\t\"fileSeparator\": \"|\",\n" +
                "\t\"id\": \"8a58a6c787c1e8e30187e4b3edd404ca\",\n" +
                "\t\"name\": \"csv文件校验模板\",\n" +
                "\t\"startLine\": \"2\",\n" +
                "\t\"status\": 1\n" +
                "}, {\n" +
                "\t\"code\": \"2\",\n" +
                "\t\"fieldList\": [{\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188571b351115d5\",\n" +
                "\t\t\"name\": \"name\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac9018857145e8d15ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188571b351115d6\",\n" +
                "\t\t\"name\": \"age\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac9018857145e8d15ca\",\n" +
                "\t\t\"type\": \"INTEGER\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188571b351115d7\",\n" +
                "\t\t\"name\": \"work\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac9018857145e8d15ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188571b351215d8\",\n" +
                "\t\t\"name\": \"message\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac9018857145e8d15ca\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}],\n" +
                "\t\"fileSeparator\": \",\",\n" +
                "\t\"id\": \"8a58a6c78855dac9018857145e8d15ca\",\n" +
                "\t\"name\": \"lyb_csv模板\",\n" +
                "\t\"startLine\": \"2\",\n" +
                "\t\"status\": 1\n" +
                "}, {\n" +
                "\t\"code\": \"2\",\n" +
                "\t\"fieldList\": [{\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188655fd7082299\",\n" +
                "\t\t\"name\": \"C1\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac90188655fd7072298\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188655fd708229a\",\n" +
                "\t\t\"name\": \"C2\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac90188655fd7072298\",\n" +
                "\t\t\"type\": \"INTEGER\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c78855dac90188655fd708229b\",\n" +
                "\t\t\"name\": \"C3\",\n" +
                "\t\t\"templateId\": \"8a58a6c78855dac90188655fd7072298\",\n" +
                "\t\t\"type\": \"DOUBLE\"\n" +
                "\t}],\n" +
                "\t\"fileSeparator\": \",\",\n" +
                "\t\"id\": \"8a58a6c78855dac90188655fd7072298\",\n" +
                "\t\"name\": \"1111\",\n" +
                "\t\"startLine\": \"2\",\n" +
                "\t\"status\": 1\n" +
                "}, {\n" +
                "\t\"code\": \"2\",\n" +
                "\t\"fieldList\": [{\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8b0020\",\n" +
                "\t\t\"name\": \"id\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8b0021\",\n" +
                "\t\t\"name\": \"type_code\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8b0022\",\n" +
                "\t\t\"name\": \"type_name_first\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8d0023\",\n" +
                "\t\t\"name\": \"type_name_second\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8d0024\",\n" +
                "\t\t\"name\": \"type_name_third\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8f0025\",\n" +
                "\t\t\"name\": \"order_num\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58a6c7889906bf0188990a4e8f0026\",\n" +
                "\t\t\"name\": \"status\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}],\n" +
                "\t\"id\": \"8a58a6c7889906bf01889908fbd40016\",\n" +
                "\t\"name\": \"dddd\",\n" +
                "\t\"status\": 1\n" +
                "}, {\n" +
                "\t\"code\": \"2\",\n" +
                "\t\"fieldList\": [{\n" +
                "\t\t\"id\": \"8a58bcf68b4aed2a018b4b9af28305b9\",\n" +
                "\t\t\"name\": \"name\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889933061c0279\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58bcf68b4aed2a018b4b9af28305ba\",\n" +
                "\t\t\"name\": \"age\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889933061c0279\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58bcf68b4aed2a018b4b9af28305bb\",\n" +
                "\t\t\"name\": \"work\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889933061c0279\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"8a58bcf68b4aed2a018b4b9af28305bc\",\n" +
                "\t\t\"name\": \"message\",\n" +
                "\t\t\"templateId\": \"8a58a6c7889906bf01889933061c0279\",\n" +
                "\t\t\"type\": \"STRING\"\n" +
                "\t}],\n" +
                "\t\"fileSeparator\": \",\",\n" +
                "\t\"id\": \"8a58a6c7889906bf01889933061c0279\",\n" +
                "\t\"name\": \"csv模板\",\n" +
                "\t\"startLine\": \"2\",\n" +
                "\t\"status\": 1\n" +
                "}]";
        List<FCTemplateDTO> fileTemplateList = JSON.parseArray(templateJsonString, FCTemplateDTO.class);

        return fileTemplateList;
    }
}